package com.webservice.xmloper.commonDataManager;

import java.util.List;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

public class Dom4jConverter {
	
	public static String updateXmlElement(String xmlString){
		Document document;
		try {
			document = DocumentHelper.parseText(xmlString);
			
			List<Element> us = document.getRootElement().selectNodes("//userInfo");
			for (int i = 0; i < us.size(); i++) {
				//System.out.println(us.get(i).element("nature").getText());
				if("1".equals(us.get(i).element("nature").getText())){
					us.get(i).element("info").setName("serviceUserInfo");
				}else{
					us.get(i).element("info").setName("OtherUserInfo");
				}
				
			}
			return document.asXML();
		} catch (DocumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		return null;
	}
}
